﻿<script>
	$(function () {
		$('[zyf-match-value]').modal('show');

		var passed = true;
		$('[zyf-er-submit-btn]').click(function () {
			let $form = $(this).parents('fakeform'),
				$formInput = $form.find('input:checkbox');
			$formInput.each(function () {
				mark($(this));
			})
			if (!passed) {
				$(this).attr('disabled', true);
				$('[zyf-error-reminder]').show();
			} else {
				$('[zyf-match-value]').modal('hide');
			}
		})

		function doCorrect($element) {
			return $element.data('correct') == $element.is(':checked')
		}

		function mark($element) {
			var $option = $element.parents('div.custom-control'),
				correct = doCorrect($element);
			if (correct) {
				$option.removeClass('bg-info text-white');
			} else {
				$option.addClass('bg-info text-white');
				$option.next().show();
			}
			//if ($option.find('.fa-question').length == 0) {
			//	$option.append('<i class="fa fa-question ml-2" onclick="showReason(event)"></i>')
			//}//else nothing
			passed = passed && correct;
		}
	})

	//function showReason(event) {
	//	$(event.target).prev().show();
	//}
</script>
